package sg.edu.nus.dbd.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import sg.edu.nus.dbd.util.MyLogger;

public abstract class BaseAction extends DispatchAction {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest req, HttpServletResponse res) throws Exception {

		HttpSession session = req.getSession(false);
		if (session.getAttribute("LOGIN_ID") == null) {
			MyLogger.debug("Not yet login");
			return mapping.findForward("login");
		} else {
			MyLogger.debug("Already login. Username is: "
					+ session.getAttribute("LOGIN_ID"));
			return performAction(mapping, form, req, res);
		}
	}

	public abstract ActionForward performAction(ActionMapping mapping,
			ActionForm form, HttpServletRequest req, HttpServletResponse res)
			throws Exception;
}
